package cn.xmy.demo01.servlet;

import cn.xmy.demo01.pojo.Type;
import cn.xmy.demo01.service.TypeService;
import cn.xmy.demo01.service.impl.TypeServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/equipServlet")
public class EquipServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TypeService typeService=new TypeServiceImpl();
        try {
            List<Type> equips = typeService.getEquip();
            String a= JSON.toJSONString(equips);
            PrintWriter out=response.getWriter();
            out.println(a);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }
}
